﻿namespace Dcms.OleDbDAL
{
    using Dcms.BaseLib;
    using Dcms.Common;
    using Dcms.IDAL;
    using Dcms.Model;
    using System;
    using System.Collections.Generic;
    using System.Data;
    using System.Data.OleDb;

    public class Dcms_CateDAL : IDcms_CateDAL
    {
        public Dcms_CateModel AddModel(Dcms_CateModel model)
        {
            string sQLString = "insert into Dcms_Cate(Cate_Name,Cate_ParentID,Cate_Image,Cate_Intro,Cate_Order,Cate_AddTime,Cate_Lang,Cate_Flag,Cate_OpType,Cate_Url,Cate_State,Cate_Depth,Cate_IsChild,Cate_Key,Cate_ModelKeyId,Cate_IsCommentFlag,Cate_IsRevertFlag,Cate_IDPath,Cate_IsMember,Cate_MemberRole,Cate_AllAction,Cate_Layer,Cate_BackCate,Cate_magstate,Cate_showtype,Cate_IsCapability,Cate_auditing,Cate_browse,Cate_Guid,Cate_ViewURL) values(@Cate_Name,@Cate_ParentID,@Cate_Image,@Cate_Intro,@Cate_Order,@Cate_AddTime,@Cate_Lang,@Cate_Flag,@Cate_OpType,@Cate_Url,@Cate_State,@Cate_Depth,@Cate_IsChild,@Cate_Key,@Cate_ModelKeyId,@Cate_IsCommentFlag,@Cate_IsRevertFlag,@Cate_IDPath,@Cate_IsMember,@Cate_MemberRole,@Cate_AllAction,@Cate_Layer,@Cate_BackCate,@Cate_magstate,@Cate_showtype,@Cate_IsCapability,@Cate_auditing,@Cate_browse,@Cate_Guid,@Cate_ViewURL)";
            OleDbParameter[] cmdParms = new OleDbParameter[] { 
                new OleDbParameter("@Cate_Name", OleDbType.VarChar), new OleDbParameter("@Cate_ParentID", OleDbType.Integer), new OleDbParameter("@Cate_Image", OleDbType.VarChar), new OleDbParameter("@Cate_Intro", OleDbType.LongVarChar), new OleDbParameter("@Cate_Order", OleDbType.Integer), new OleDbParameter("@Cate_AddTime", OleDbType.DBTimeStamp), new OleDbParameter("@Cate_Lang", OleDbType.VarChar), new OleDbParameter("@Cate_Flag", OleDbType.VarChar), new OleDbParameter("@Cate_OpType", OleDbType.VarChar), new OleDbParameter("@Cate_Url", OleDbType.VarChar), new OleDbParameter("@Cate_State", OleDbType.VarChar), new OleDbParameter("@Cate_Depth", OleDbType.VarChar), new OleDbParameter("@Cate_IsChild", OleDbType.Integer), new OleDbParameter("@Cate_Key", OleDbType.VarChar), new OleDbParameter("@Cate_ModelKeyId", OleDbType.SmallInt), new OleDbParameter("@Cate_IsCommentFlag", OleDbType.SmallInt), 
                new OleDbParameter("@Cate_IsRevertFlag", OleDbType.SmallInt), new OleDbParameter("@Cate_IDPath", OleDbType.VarChar), new OleDbParameter("@Cate_IsMember", OleDbType.VarChar), new OleDbParameter("@Cate_MemberRole", OleDbType.VarChar), new OleDbParameter("@Cate_AllAction", OleDbType.VarChar), new OleDbParameter("@Cate_Layer", OleDbType.SmallInt), new OleDbParameter("@Cate_BackCate", OleDbType.SmallInt), new OleDbParameter("@Cate_magstate", OleDbType.SmallInt), new OleDbParameter("@Cate_showtype", OleDbType.SmallInt), new OleDbParameter("@Cate_IsCapability", OleDbType.SmallInt), new OleDbParameter("@Cate_auditing", OleDbType.SmallInt), new OleDbParameter("@Cate_browse", OleDbType.SmallInt), new OleDbParameter("@Cate_Guid", OleDbType.VarChar), new OleDbParameter("@Cate_ViewURL", OleDbType.VarChar)
             };
            cmdParms[0].Value = model.Cate_Name;
            cmdParms[1].Value = model.Cate_ParentID;
            cmdParms[2].Value = model.Cate_Image;
            cmdParms[3].Value = model.Cate_Intro;
            cmdParms[4].Value = model.Cate_Order;
            cmdParms[5].Value = model.Cate_AddTime;
            cmdParms[6].Value = model.Cate_Lang;
            cmdParms[7].Value = model.Cate_Flag;
            cmdParms[8].Value = model.Cate_OpType;
            cmdParms[9].Value = model.Cate_Url;
            cmdParms[10].Value = model.Cate_State;
            cmdParms[11].Value = model.Cate_Depth;
            cmdParms[12].Value = model.Cate_IsChild;
            cmdParms[13].Value = model.Cate_Key;
            cmdParms[14].Value = model.Cate_ModelKeyId;
            cmdParms[15].Value = model.Cate_IsCommentFlag;
            cmdParms[0x10].Value = model.Cate_IsRevertFlag;
            cmdParms[0x11].Value = model.Cate_IDPath;
            cmdParms[0x12].Value = model.Cate_IsMember;
            cmdParms[0x13].Value = model.Cate_MemberRole;
            cmdParms[20].Value = model.Cate_AllAction;
            cmdParms[0x15].Value = model.Cate_Layer;
            cmdParms[0x16].Value = model.Cate_BackCate;
            cmdParms[0x17].Value = model.Cate_magstate;
            cmdParms[0x18].Value = model.Cate_showtype;
            cmdParms[0x19].Value = model.Cate_IsCapability;
            cmdParms[0x1a].Value = model.Cate_auditing;
            cmdParms[0x1b].Value = model.Cate_browse;
            cmdParms[0x1c].Value = model.Cate_Guid;
            cmdParms[0x1d].Value = model.Cate_ViewURL;
            OleDbHelper.ExecuteSql("update Dcms_Cate set Cate_IsChild=0, Cate_OpType='ADDONLY' where Cate_ID=" + model.Cate_ParentID, null);
            OleDbHelper.ExecuteSql(sQLString, cmdParms);
            string str3 = "select top 1 Cate_ID from Dcms_Cate where Cate_Name=@Cate_Name order by Cate_ID desc";
            OleDbParameter[] parameterArray2 = new OleDbParameter[] { new OleDbParameter("@Cate_Name", OleDbType.VarChar) };
            parameterArray2[0].Value = model.Cate_Name;
            model.Cate_ID = Convert.ToInt32(OleDbHelper.GetSingle(str3, parameterArray2));
            if (string.IsNullOrEmpty(model.Cate_IDPath))
                model.Cate_IDPath = "," + model.Cate_ID.ToString() + ",";
            else
                model.Cate_IDPath = model.Cate_IDPath + model.Cate_ID.ToString() + ",";
            this.Update(model);
            return model;
        }

        public IList<Dcms_CateModel> DataSetToList(DataSet ds)
        {
            IList<Dcms_CateModel> list = new List<Dcms_CateModel>();
            for (int i = 0; i < ds.Tables[0].Rows.Count; i++)
            {
                Dcms_CateModel item = new Dcms_CateModel();
                if (ds.Tables[0].Rows[i]["Cate_ID"].ToString() != "") item.Cate_ID = int.Parse(ds.Tables[0].Rows[i]["Cate_ID"].ToString());
                item.Cate_Name = ds.Tables[0].Rows[i]["Cate_Name"].ToString();
                if (ds.Tables[0].Rows[i]["Cate_ParentID"].ToString() != "") item.Cate_ParentID = int.Parse(ds.Tables[0].Rows[i]["Cate_ParentID"].ToString());
                item.Cate_Image = ds.Tables[0].Rows[i]["Cate_Image"].ToString();
                item.Cate_Intro = ds.Tables[0].Rows[i]["Cate_Intro"].ToString();
                if (ds.Tables[0].Rows[i]["Cate_Order"].ToString() != "") item.Cate_Order = int.Parse(ds.Tables[0].Rows[i]["Cate_Order"].ToString());
                if (ds.Tables[0].Rows[i]["Cate_AddTime"].ToString() != "") item.Cate_AddTime = DateTime.Parse(ds.Tables[0].Rows[i]["Cate_AddTime"].ToString());
                item.Cate_Lang = ds.Tables[0].Rows[i]["Cate_Lang"].ToString();
                item.Cate_Flag = ds.Tables[0].Rows[i]["Cate_Flag"].ToString();
                item.Cate_OpType = ds.Tables[0].Rows[i]["Cate_OpType"].ToString();
                item.Cate_Url = ds.Tables[0].Rows[i]["Cate_Url"].ToString();
                item.Cate_State = ds.Tables[0].Rows[i]["Cate_State"].ToString();
                item.Cate_Depth = ds.Tables[0].Rows[i]["Cate_Depth"].ToString();
                item.Cate_IsMember = ds.Tables[0].Rows[i]["Cate_IsMember"].ToString();
                item.Cate_MemberRole = ds.Tables[0].Rows[i]["Cate_MemberRole"].ToString();
                if (ds.Tables[0].Rows[i]["Cate_IsChild"].ToString() != "") item.Cate_IsChild = int.Parse(ds.Tables[0].Rows[i]["Cate_IsChild"].ToString());
                item.Cate_Key = ds.Tables[0].Rows[i]["Cate_Key"].ToString();
                if (ds.Tables[0].Rows[i]["Cate_ModelKeyId"].ToString() != "") item.Cate_ModelKeyId = int.Parse(ds.Tables[0].Rows[i]["Cate_ModelKeyId"].ToString());
                if (ds.Tables[0].Rows[i]["Cate_IsCommentFlag"].ToString() != "") item.Cate_IsCommentFlag = int.Parse(ds.Tables[0].Rows[i]["Cate_IsCommentFlag"].ToString());
                if (ds.Tables[0].Rows[i]["Cate_IsRevertFlag"].ToString() != "") item.Cate_IsRevertFlag = int.Parse(ds.Tables[0].Rows[i]["Cate_IsRevertFlag"].ToString());
                item.Cate_IDPath = ds.Tables[0].Rows[i]["Cate_IDPath"].ToString();
                item.Cate_AllAction = ds.Tables[0].Rows[i]["Cate_AllAction"].ToString();
                if (ds.Tables[0].Rows[i]["Cate_Layer"].ToString() != "") item.Cate_Layer = int.Parse(ds.Tables[0].Rows[i]["Cate_Layer"].ToString());
                if (ds.Tables[0].Rows[i]["Cate_BackCate"].ToString() != "") item.Cate_BackCate = int.Parse(ds.Tables[0].Rows[i]["Cate_BackCate"].ToString());
                if (ds.Tables[0].Rows[i]["Cate_magstate"].ToString() != "") item.Cate_magstate = int.Parse(ds.Tables[0].Rows[i]["Cate_magstate"].ToString());
                if (ds.Tables[0].Rows[i]["Cate_showtype"].ToString() != "") item.Cate_showtype = int.Parse(ds.Tables[0].Rows[i]["Cate_showtype"].ToString());
                if (ds.Tables[0].Rows[i]["Cate_IsCapability"].ToString() != "") item.Cate_IsCapability = int.Parse(ds.Tables[0].Rows[i]["Cate_IsCapability"].ToString());
                if (ds.Tables[0].Rows[i]["Cate_auditing"].ToString() != "") item.Cate_auditing = int.Parse(ds.Tables[0].Rows[i]["Cate_auditing"].ToString());
                if (ds.Tables[0].Rows[i]["Cate_browse"].ToString() != "") item.Cate_browse = int.Parse(ds.Tables[0].Rows[i]["Cate_browse"].ToString());
                item.Cate_Guid = ds.Tables[0].Rows[i]["Cate_Guid"].ToString();
                item.Cate_ViewURL = ds.Tables[0].Rows[i]["Cate_ViewURL"].ToString();
                list.Add(item);
            }
            return list;
        }

        public bool DelAll()
        {
            try
            {
                string sQLString = "delete from Dcms_Cate where 1=@sqlwhere";
                OleDbParameter[] cmdParms = new OleDbParameter[] { new OleDbParameter("@sqlwhere", OleDbType.SmallInt) };
                cmdParms[0].Value = 1;
                OleDbHelper.ExecuteSql(sQLString, cmdParms);
                return true;
            }
            catch
            {
                return false;
            }
        }

        public void DeleteModelByFlag(string Flag)
        {
            string sQLString = "delete from Dcms_Cate where Cate_Flag=@Cate_Flag";
            OleDbParameter[] cmdParms = new OleDbParameter[] { new OleDbParameter("@Cate_Flag", OleDbType.VarChar) };
            cmdParms[0].Value = Flag;
            OleDbHelper.ExecuteSql(sQLString, cmdParms);
        }

        public void DeleteModelByFlag(string Flag, int ModelID)
        {
            string sQLString = "delete from Dcms_Cate where Cate_Flag=@Cate_Flag and Cate_ModelKeyId=@Cate_ModelKeyId";
            OleDbParameter[] cmdParms = new OleDbParameter[] { new OleDbParameter("@Cate_Flag", OleDbType.VarChar), new OleDbParameter("@Cate_ModelKeyId", OleDbType.Integer) };
            cmdParms[0].Value = Flag;
            cmdParms[1].Value = ModelID;
            OleDbHelper.ExecuteSql(sQLString, cmdParms);
        }

        public void DeleteModelByID(int ID)
        {
            Dcms_CateModel modelByID = new Dcms_CateModel();
            modelByID = this.GetModelByID(ID);
            if (OleDbHelper.GetNoteCount("select count(Cate_ID) from Dcms_Cate where Cate_ParentID=" + modelByID.Cate_ParentID) <= 1) OleDbHelper.ExecuteSql("update Dcms_Cate set Cate_IsChild=1 where Cate_ID=" + modelByID.Cate_ParentID, null);
            string sQLString = "delete from Dcms_Cate where Cate_ID=@Cate_ID";
            OleDbParameter[] cmdParms = new OleDbParameter[] { new OleDbParameter("@Cate_ID", OleDbType.Integer) };
            cmdParms[0].Value = ID;
            OleDbHelper.ExecuteSql(sQLString, cmdParms);
        }

        public void DeleteModelListByLanguage(string LangVerStr)
        {
            string sQLString = "delete  from Dcms_Cate where Cate_Lang=@Cate_Lang";
            OleDbParameter[] cmdParms = new OleDbParameter[] { new OleDbParameter("@Cate_Lang", OleDbType.VarChar) };
            cmdParms[0].Value = LangVerStr;
            OleDbHelper.ExecuteSql(sQLString, cmdParms);
        }

        public bool DelGuid(string guid)
        {
            string sQLString = "delete  from Dcms_Cate where Cate_Guid=@Cate_Guid";
            OleDbParameter[] cmdParms = new OleDbParameter[] { new OleDbParameter("@Cate_Guid", OleDbType.VarChar) };
            cmdParms[0].Value = guid;
            return OleDbHelper.ExecuteSql(sQLString, cmdParms) > 0;
        }

        public string GetAllSubCateIdList(string CurrCateId, string LangVerStr, int CateType, string isMember, string Role)
        {
            string oneFileValue = "";
            string str2 = "";
            DataTable table = new DataTable();
            OleDbParameter[] commandParameters = new OleDbParameter[] { new OleDbParameter("MyCateKey", OleDbType.VarChar, 0x1388), new OleDbParameter("mylangver", OleDbType.VarChar, 50), new OleDbParameter("CateRole", OleDbType.VarChar, 500) };
            commandParameters[0].Value = CurrCateId;
            commandParameters[1].Value = LangVerStr;
            commandParameters[2].Value = Role;
            if (isMember == "0" && CateType == 1)
                oneFileValue = DcmsDataBaseHelper.GetOneFileValue("select Cate_IDPath from Dcms_Cate where  Cate_ID=" + CurrCateId, "0");
            else if (isMember == "0" && CateType != 1)
                oneFileValue = DcmsDataBaseHelper.GetOneFileValue("select Cate_IDPath from Dcms_Cate where Cate_Key=@MyCateKey and Cate_Lang=@mylangver", "0", commandParameters);
            else
            {
                string cmdText = "select Cate_IDPath from Dcms_Cate where (Cate_MemberRole like '%" + Role + "%' or Cate_MemberRole like '%|0|%')";
                if (CateType == 1)
                    cmdText = cmdText + " and Cate_ID=" + CurrCateId;
                else
                    cmdText = cmdText + " and Cate_Key=@MyCateKey and Cate_Lang=@mylangver";
                oneFileValue = DcmsDataBaseHelper.GetOneFileValue(cmdText, "-1", commandParameters);
            }
            table = DcmsDataBaseHelper.ExecuteTable("select Cate_ID from Dcms_Cate where Cate_IDPath like'" + oneFileValue + "%' and Cate_IDPath<>'" + oneFileValue + "'", CommandType.Text, null);
            for (int i = 0; i < table.Rows.Count; i++)
            {
                str2 = str2 + table.Rows[i]["Cate_ID"].ToString() + ",";
            }
            if (str2.Length > 0) return str2.Substring(0, str2.Length - 1);
            return "0";
        }

        public Dcms_CateModel GetCateByFalyOrder(string Faly, int order, string lang)
        {
            string sQLString = "select * from Dcms_Cate where Cate_Flag=@Cate_Flag and  Cate_ModelKeyId=@Cate_ModelKeyId and  Cate_Lang=@Cate_Lang ";
            OleDbParameter[] cmdParms = new OleDbParameter[] { new OleDbParameter("@Cate_Flag", OleDbType.VarChar), new OleDbParameter("@Cate_ModelKeyId", OleDbType.Integer), new OleDbParameter("@Cate_Lang", OleDbType.VarChar) };
            cmdParms[0].Value = Faly;
            cmdParms[1].Value = order;
            cmdParms[2].Value = lang;
            DataSet ds = OleDbHelper.CreateDataSet(sQLString, cmdParms);
            IList<Dcms_CateModel> list = this.DataSetToList(ds);
            return ((list.Count > 0) ? list[0] : null);
        }

        public int GetCateIsChild(int CateID)
        {
            return OleDbHelper.GetNoteCount("select Cate_IsChild from Dcms_Cate where Cate_ID=" + CateID);
        }

        public string GetChildCateId(int CateID)
        {
            string str = string.Empty;
            DataSet set = OleDbHelper.CreateDataSet("select Cate_ID from Dcms_Cate where Cate_ParentID=" + CateID);
            for (int i = 0; i < set.Tables[0].Rows.Count; i++)
            {
                if (i == 0)
                    str = set.Tables[0].Rows[i][0].ToString();
                else
                    str = str + "," + set.Tables[0].Rows[i][0].ToString();
            }
            return str;
        }

        public string GetDataCount(string SqlStr)
        {
            return OleDbHelper.GetNoteCount(SqlStr).ToString();
        }

        public IList<Dcms_CateModel> GetDataListByPage(string SqlStr, int CurPage, int PageSize)
        {
            return this.DataSetToList(OleDbHelper.CreateDataSet(SqlStr, (CurPage - 1) * PageSize, PageSize));
        }

        public string GetHorCateIdList(string CurrCateId, string LangVerStr, int CateType, string isMember, string Role)
        {
            string oneFileValue = "";
            string str2 = "";
            DataTable table = new DataTable();
            OleDbParameter[] commandParameters = new OleDbParameter[] { new OleDbParameter("MyCateKey", OleDbType.VarChar, 0x1388), new OleDbParameter("mylangver", OleDbType.VarChar, 50), new OleDbParameter("CateRole", OleDbType.VarChar, 500) };
            commandParameters[0].Value = CurrCateId;
            commandParameters[1].Value = LangVerStr;
            commandParameters[2].Value = Role;
            if (isMember == "0" && CateType == 1)
                oneFileValue = DcmsDataBaseHelper.GetOneFileValue("select Cate_ParentID from Dcms_Cate where Cate_ID=" + CurrCateId, "0");
            else if (isMember == "0" && CateType != 1)
                oneFileValue = DcmsDataBaseHelper.GetOneFileValue("select Cate_ParentID from Dcms_Cate where Cate_Key=@MyCateKey and Cate_Lang=@mylangver", "0", commandParameters);
            else
            {
                string cmdText = "select Cate_ParentID from Dcms_Cate where (Cate_MemberRole like '%" + Role + "%' or Cate_MemberRole like '%|0|%')";
                if (CateType == 1)
                    cmdText = cmdText + " and Cate_ID=" + CurrCateId;
                else
                    cmdText = cmdText + " and Cate_Key=@MyCateKey and Cate_Lang=@mylangver";
                oneFileValue = DcmsDataBaseHelper.GetOneFileValue(cmdText, "-1", commandParameters);
            }
            table = DcmsDataBaseHelper.ExecuteTable("select Cate_ID from Dcms_Cate where Cate_ParentID=" + oneFileValue, CommandType.Text, null);
            for (int i = 0; i < table.Rows.Count; i++)
            {
                str2 = str2 + table.Rows[i]["Cate_ID"].ToString() + ",";
            }
            if (str2.Length > 0) return str2.Substring(0, str2.Length - 1);
            return "0";
        }

        public DataSet GetList(string SqlWhere)
        {
            string str = "select * from  Dcms_Cate";
            if (SqlWhere != "") str = str + " where " + SqlWhere;
            return OleDbHelper.CreateDataSet(str + " order by Cate_Order, Cate_ID asc");
        }

        public int GetMaxId()
        {
            string maxNoteID = OleDbHelper.GetMaxNoteID("Cate_ID", "Dcms_Cate");
            switch (maxNoteID)
            {
                case "":
                case null:
                    return 0;
            }
            return Convert.ToInt32(maxNoteID);
        }

        public Dcms_CateModel GetModelByFlag(string Flag)
        {
            string sQLString = "select * from Dcms_Cate where Cate_ParentID=0 and Cate_Flag=@Cate_Flag";
            OleDbParameter[] cmdParms = new OleDbParameter[] { new OleDbParameter("@Cate_Flag", OleDbType.VarChar) };
            cmdParms[0].Value = Flag;
            Dcms_CateModel model = new Dcms_CateModel();
            DataSet ds = OleDbHelper.CreateDataSet(sQLString, cmdParms);
            IList<Dcms_CateModel> list = this.DataSetToList(ds);
            return ((list.Count > 0) ? list[0] : null);
        }

        public Dcms_CateModel GetModelByFlag(string Flag, int ModelKeyID, string LangVerStr)
        {
            string sQLString = "select * from Dcms_Cate where Cate_ParentID=0 and Cate_Flag=@Cate_Flag and Cate_ModelKeyId=@Cate_ModelKeyId and Cate_Lang=@Cate_Lang";
            OleDbParameter[] cmdParms = new OleDbParameter[] { new OleDbParameter("@Cate_Flag", OleDbType.VarChar), new OleDbParameter("@Cate_ModelKeyId", OleDbType.SmallInt), new OleDbParameter("@Cate_Lang", OleDbType.VarChar) };
            cmdParms[0].Value = Flag;
            cmdParms[1].Value = ModelKeyID;
            cmdParms[2].Value = LangVerStr;
            Dcms_CateModel model = new Dcms_CateModel();
            DataSet ds = OleDbHelper.CreateDataSet(sQLString, cmdParms);
            IList<Dcms_CateModel> list = this.DataSetToList(ds);
            return ((list.Count > 0) ? list[0] : null);
        }

        public Dcms_CateModel GetModelByGuid(string guid)
        {
            string sQLString = "select * from Dcms_Cate where Cate_Guid=@Cate_Guid";
            OleDbParameter[] cmdParms = new OleDbParameter[] { new OleDbParameter("@Cate_Guid", OleDbType.VarChar) };
            cmdParms[0].Value = guid;
            Dcms_CateModel model = new Dcms_CateModel();
            DataSet ds = OleDbHelper.CreateDataSet(sQLString, cmdParms);
            IList<Dcms_CateModel> list = this.DataSetToList(ds);
            return ((list.Count > 0) ? list[0] : null);
        }

        public Dcms_CateModel GetModelByID(int ID)
        {
            string sQLString = "select * from Dcms_Cate where Cate_ID=@Cate_ID";
            OleDbParameter[] cmdParms = new OleDbParameter[] { new OleDbParameter("@Cate_ID", OleDbType.Integer) };
            cmdParms[0].Value = ID;
            Dcms_CateModel model = new Dcms_CateModel();
            DataSet ds = OleDbHelper.CreateDataSet(sQLString, cmdParms);
            IList<Dcms_CateModel> list = this.DataSetToList(ds);
            return ((list.Count > 0) ? list[0] : null);
        }

        public DataSet GetModelList()
        {
            string sql = "select * from Dcms_Cate";
            return OleDbHelper.CreateDataSet(sql);
        }

        public IList<Dcms_CateModel> GetModelListByLanguage(string LangVerStr)
        {
            string sQLString = "select * from Dcms_Cate where Cate_Lang=@Cate_Lang order by Cate_IDPath";
            OleDbParameter[] cmdParms = new OleDbParameter[] { new OleDbParameter("@Cate_Lang", OleDbType.VarChar) };
            cmdParms[0].Value = LangVerStr;
            return this.DataSetToList(OleDbHelper.CreateDataSet(sQLString, cmdParms));
        }

        public DataSet GetSubCategory(int iCategoryID, string Language)
        {
            string sQLString = "Select Cate_ID,Cate_Name,Cate_ParentID,Cate_magstate,Cate_Order,Cate_Lang,Cate_Flag,Cate_OpType,Cate_IsChild from Dcms_Cate Where Cate_ParentID=@Cate_ParentID And Cate_Lang=@Cate_Lang Order By Cate_Order, Cate_ID Asc";
            OleDbParameter[] cmdParms = new OleDbParameter[] { new OleDbParameter("@Cate_ParentID", OleDbType.Integer), new OleDbParameter("@Cate_Lang", OleDbType.VarChar) };
            cmdParms[0].Value = iCategoryID;
            cmdParms[1].Value = Language;
            return OleDbHelper.CreateDataSet(sQLString, cmdParms);
        }

        public string GetSubCateIdList(string CurrCateId, string LangVerStr, int CateType, string isMember, string Role)
        {
            string str = "";
            string str2 = "";
            DataTable table = new DataTable();
            OleDbParameter[] commandParameters = new OleDbParameter[] { new OleDbParameter("MyCateKey", OleDbType.VarChar, 0x1388), new OleDbParameter("mylangver", OleDbType.VarChar, 50), new OleDbParameter("CateRole", OleDbType.VarChar, 500) };
            commandParameters[0].Value = CurrCateId;
            commandParameters[1].Value = LangVerStr;
            commandParameters[2].Value = Role;
            if (isMember == "0" && CateType == 1)
                str = CurrCateId;
            else if (isMember == "0" && CateType != 1)
                str = DcmsDataBaseHelper.GetOneFileValue("select Cate_ID from Dcms_Cate where Cate_Key=@MyCateKey and Cate_Lang=@mylangver", "0", commandParameters);
            else
            {
                string cmdText = "select Cate_ID from Dcms_Cate where (Cate_MemberRole like '%" + Role + "%' or Cate_MemberRole like '%|0|%')";
                if (CateType == 1)
                    cmdText = cmdText + " and Cate_ID=" + CurrCateId;
                else
                    cmdText = cmdText + " and Cate_Key=@MyCateKey and Cate_Lang=@mylangver";
                str = DcmsDataBaseHelper.GetOneFileValue(cmdText, "-1", commandParameters);
            }
            table = DcmsDataBaseHelper.ExecuteTable("select Cate_ID from Dcms_Cate where Cate_ParentID=" + str, CommandType.Text, null);
            for (int i = 0; i < table.Rows.Count; i++)
            {
                str2 = str2 + table.Rows[i]["Cate_ID"].ToString() + ",";
            }
            if (str2.Length > 0) return str2.Substring(0, str2.Length - 1);
            return "0";
        }

        public string GetSupCateIdList(string ChildCateId, string LangVerStr, int CateType, string isMember, string Role)
        {
            string str;
            OleDbParameter[] commandParameters = new OleDbParameter[] { new OleDbParameter("MyCateKey", OleDbType.VarChar, 0x1388), new OleDbParameter("mylangver", OleDbType.VarChar, 50), new OleDbParameter("CateRole", OleDbType.VarChar, 500) };
            commandParameters[0].Value = ChildCateId;
            commandParameters[1].Value = LangVerStr;
            commandParameters[2].Value = Role;
            if (isMember == "0" && CateType == 1) return DcmsDataBaseHelper.GetOneFileValue("select Cate_ParentID from Dcms_Cate where Cate_ID=" + ChildCateId, "0");
            if (isMember == "0" && CateType != 1)
            {
                str = "select Cate_ID from Dcms_Cate where Cate_Key=@MyCateKey and Cate_Lang=@mylangver";
                return DcmsDataBaseHelper.GetOneFileValue(str, "0", commandParameters);
            }
            str = "select Cate_ID from Dcms_Cate where (Cate_MemberRole like '%" + Role + "%' or Cate_MemberRole like '%|0|%')";
            if (CateType == 1)
                str = str + " and Cate_ID=" + ChildCateId;
            else
                str = str + " and Cate_Key=@MyCateKey and Cate_Lang=@mylangver";
            return DcmsDataBaseHelper.GetOneFileValue(str, "0", commandParameters);
        }

        public string GetThisAndAllSubCateIdList(string CurrCateId, string LangVerStr, int CateType, string isMember, string Role)
        {
            string oneFileValue = "";
            string str2 = "";
            DataTable table = new DataTable();
            OleDbParameter[] commandParameters = new OleDbParameter[] { new OleDbParameter("MyCateKey", OleDbType.VarChar, 0x1388), new OleDbParameter("mylangver", OleDbType.VarChar, 50), new OleDbParameter("CateRole", OleDbType.VarChar, 500) };
            commandParameters[0].Value = CurrCateId;
            commandParameters[1].Value = LangVerStr;
            commandParameters[2].Value = Role;
            if (isMember == "0" && CateType == 1)
                oneFileValue = DcmsDataBaseHelper.GetOneFileValue("select Cate_IDPath from Dcms_Cate where Cate_ID=" + CurrCateId, "0");
            else if (isMember == "0" && CateType != 1)
                oneFileValue = DcmsDataBaseHelper.GetOneFileValue("select Cate_IDPath from Dcms_Cate where Cate_Key=@MyCateKey and Cate_Lang=@mylangver", "0", commandParameters);
            else
            {
                string cmdText = "select Cate_IDPath from Dcms_Cate where (Cate_MemberRole like '%" + Role + "%' or Cate_MemberRole like '%|0|%')";
                if (CateType == 1)
                    cmdText = cmdText + " and Cate_ID=" + CurrCateId;
                else
                    cmdText = cmdText + " and Cate_Key=@MyCateKey and Cate_Lang=@mylangver";
                oneFileValue = DcmsDataBaseHelper.GetOneFileValue(cmdText, "-1", commandParameters);
            }
            table = DcmsDataBaseHelper.ExecuteTable("select Cate_ID from Dcms_Cate where Cate_IDPath like'" + oneFileValue + "%'", CommandType.Text, null);
            for (int i = 0; i < table.Rows.Count; i++)
            {
                str2 = str2 + table.Rows[i]["Cate_ID"].ToString() + ",";
            }
            if (str2.Length > 0) return str2.Substring(0, str2.Length - 1);
            return "0";
        }

        public string GetThisAndSubCateIdList(string CurrCateId, string LangVerStr, int CateType, string isMember, string Role)
        {
            string str = "";
            string str2 = "";
            DataTable table = new DataTable();
            OleDbParameter[] commandParameters = new OleDbParameter[] { new OleDbParameter("MyCateKey", OleDbType.VarChar, 0x1388), new OleDbParameter("mylangver", OleDbType.VarChar, 50), new OleDbParameter("CateRole", OleDbType.VarChar, 500) };
            commandParameters[0].Value = CurrCateId;
            commandParameters[1].Value = LangVerStr;
            commandParameters[2].Value = Role;
            if (isMember == "0" && CateType == 1)
                str = CurrCateId;
            else if (isMember == "0" && CateType != 1)
                str = DcmsDataBaseHelper.GetOneFileValue("select Cate_ID from Dcms_Cate where Cate_Key=@MyCateKey and Cate_Lang=@mylangver", "0", commandParameters);
            else
            {
                string cmdText = "select Cate_ID from Dcms_Cate where (Cate_MemberRole like '%" + Role + "%' or Cate_MemberRole like '%|0|%')";
                if (CateType == 1)
                    cmdText = cmdText + " and Cate_ID=" + CurrCateId;
                else
                    cmdText = cmdText + " and Cate_Key=@MyCateKey and Cate_Lang=@mylangver";
                str = DcmsDataBaseHelper.GetOneFileValue(cmdText, "-1", commandParameters);
            }
            table = DcmsDataBaseHelper.ExecuteTable("select Cate_ID from Dcms_Cate where Cate_ParentID=" + str, CommandType.Text, null);
            for (int i = 0; i < table.Rows.Count; i++)
            {
                str2 = str2 + table.Rows[i]["Cate_ID"].ToString() + ",";
            }
            if (str2.Length > 0) return (str2 + str);
            return str;
        }

        public string GetThisCateId(string ChildCateId, string LangVerStr, int CateType, string isMember, string Role)
        {
            string str;
            OleDbParameter[] commandParameters = new OleDbParameter[] { new OleDbParameter("MyCateKey", OleDbType.VarChar, 0x1388), new OleDbParameter("mylangver", OleDbType.VarChar, 50), new OleDbParameter("CateRole", OleDbType.VarChar, 500) };
            commandParameters[0].Value = ChildCateId;
            commandParameters[1].Value = LangVerStr;
            commandParameters[2].Value = Role;
            if (isMember == "0" && CateType == 1) return ChildCateId;
            if (isMember == "0" && CateType != 1)
            {
                str = "select Cate_ID from Dcms_Cate where Cate_Key=@MyCateKey and Cate_Lang=@mylangver";
                return DcmsDataBaseHelper.GetOneFileValue(str, "0", commandParameters);
            }
            str = "select Cate_ID from Dcms_Cate where (Cate_MemberRole like '%" + Role + "%' or Cate_MemberRole like '%|0|%')";
            if (CateType == 1)
                str = str + " and Cate_ID=" + ChildCateId;
            else
                str = str + " and Cate_Key=@MyCateKey and Cate_Lang=@mylangver";
            return DcmsDataBaseHelper.GetOneFileValue(str, "0", commandParameters);
        }

        public int GetTopCateIdByFlag(string Flag, int ModelKeyID, string Lang)
        {
            return OleDbHelper.GetNoteCount("Select Cate_ID From Dcms_Cate Where Cate_ParentID=0 And Cate_Flag='" + Flag + "' And Cate_ModelKeyId = " + ModelKeyID.ToString() + " And Cate_Lang='" + Lang + "'");
        }

        public Dcms_CateModel GuidUpdate(Dcms_CateModel model)
        {
            string sQLString = "update Dcms_Cate set Cate_Name=@Cate_Name,Cate_ParentID=@Cate_ParentID,Cate_Image=@Cate_Image,Cate_Intro=@Cate_Intro,Cate_Order=@Cate_Order,Cate_AddTime=@Cate_AddTime,Cate_Lang=@Cate_Lang,Cate_Flag=@Cate_Flag,Cate_OpType=@Cate_OpType,Cate_Url=@Cate_Url,Cate_State=@Cate_State,Cate_Depth=@Cate_Depth,Cate_IsChild=@Cate_IsChild,Cate_Key=@Cate_Key,Cate_ModelKeyId=@Cate_ModelKeyId,Cate_IsCommentFlag=@Cate_IsCommentFlag,Cate_IsRevertFlag=@Cate_IsRevertFlag,Cate_IDPath=@Cate_IDPath,Cate_IsMember=@Cate_IsMember,Cate_MemberRole=@Cate_MemberRole,Cate_AllAction=@Cate_AllAction, Cate_Layer=@Cate_Layer,Cate_BackCate=@Cate_BackCate, Cate_magstate=@Cate_magstate, Cate_showtype=@Cate_showtype, Cate_IsCapability=@Cate_IsCapability,Cate_auditing=@Cate_auditing,Cate_browse=@Cate_browse ,Cate_ViewURL=@Cate_ViewURL where Cate_Guid=@Cate_Guid";
            OleDbParameter[] cmdParms = new OleDbParameter[] { 
                new OleDbParameter("@Cate_Name", OleDbType.VarChar), new OleDbParameter("@Cate_ParentID", OleDbType.Integer), new OleDbParameter("@Cate_Image", OleDbType.VarChar), new OleDbParameter("@Cate_Intro", OleDbType.LongVarChar), new OleDbParameter("@Cate_Order", OleDbType.Integer), new OleDbParameter("@Cate_AddTime", OleDbType.DBTimeStamp), new OleDbParameter("@Cate_Lang", OleDbType.VarChar), new OleDbParameter("@Cate_Flag", OleDbType.VarChar), new OleDbParameter("@Cate_OpType", OleDbType.VarChar), new OleDbParameter("@Cate_Url", OleDbType.VarChar), new OleDbParameter("@Cate_State", OleDbType.VarChar), new OleDbParameter("@Cate_Depth", OleDbType.VarChar), new OleDbParameter("@Cate_IsChild", OleDbType.Integer), new OleDbParameter("@Cate_Key", OleDbType.VarChar), new OleDbParameter("@Cate_ModelKeyId", OleDbType.SmallInt), new OleDbParameter("@Cate_IsCommentFlag", OleDbType.SmallInt), 
                new OleDbParameter("@Cate_IsRevertFlag", OleDbType.SmallInt), new OleDbParameter("@Cate_IDPath", OleDbType.VarChar), new OleDbParameter("@Cate_IsMember", OleDbType.VarChar), new OleDbParameter("@Cate_MemberRole", OleDbType.VarChar), new OleDbParameter("@Cate_AllAction", OleDbType.VarChar), new OleDbParameter("@Cate_Layer", OleDbType.SmallInt), new OleDbParameter("@Cate_BackCate", OleDbType.SmallInt), new OleDbParameter("@Cate_magstate", OleDbType.SmallInt), new OleDbParameter("@Cate_showtype", OleDbType.SmallInt), new OleDbParameter("@Cate_IsCapability", OleDbType.SmallInt), new OleDbParameter("@Cate_auditing", OleDbType.SmallInt), new OleDbParameter("@Cate_browse", OleDbType.SmallInt), new OleDbParameter("@Cate_Guid", OleDbType.VarChar), new OleDbParameter("@Cate_ViewURL", OleDbType.VarChar)
             };
            cmdParms[0].Value = model.Cate_Name;
            cmdParms[1].Value = model.Cate_ParentID;
            cmdParms[2].Value = model.Cate_Image;
            cmdParms[3].Value = model.Cate_Intro;
            cmdParms[4].Value = model.Cate_Order;
            cmdParms[5].Value = model.Cate_AddTime;
            cmdParms[6].Value = model.Cate_Lang;
            cmdParms[7].Value = model.Cate_Flag;
            cmdParms[8].Value = model.Cate_OpType;
            cmdParms[9].Value = model.Cate_Url;
            cmdParms[10].Value = model.Cate_State;
            cmdParms[11].Value = model.Cate_Depth;
            cmdParms[12].Value = model.Cate_IsChild;
            cmdParms[13].Value = model.Cate_Key;
            cmdParms[14].Value = model.Cate_ModelKeyId;
            cmdParms[15].Value = model.Cate_IsCommentFlag;
            cmdParms[0x10].Value = model.Cate_IsRevertFlag;
            cmdParms[0x11].Value = model.Cate_IDPath;
            cmdParms[0x12].Value = model.Cate_IsMember;
            cmdParms[0x13].Value = model.Cate_MemberRole;
            cmdParms[20].Value = model.Cate_AllAction;
            cmdParms[0x15].Value = model.Cate_Layer;
            cmdParms[0x16].Value = model.Cate_BackCate;
            cmdParms[0x17].Value = model.Cate_magstate;
            cmdParms[0x18].Value = model.Cate_showtype;
            cmdParms[0x19].Value = model.Cate_IsCapability;
            cmdParms[0x1a].Value = model.Cate_auditing;
            cmdParms[0x1b].Value = model.Cate_browse;
            cmdParms[0x1c].Value = model.Cate_Guid;
            cmdParms[0x1d].Value = model.Cate_ViewURL;
            OleDbHelper.ExecuteSql("update Dcms_Cate set Cate_IsChild=0 where Cate_Guid='" + model.Cate_Guid + "'", null);
            OleDbHelper.ExecuteSql(sQLString, cmdParms);
            return model;
        }

        public Dcms_CateModel Update(Dcms_CateModel model)
        {
            string sQLString = "update Dcms_Cate set Cate_Name=@Cate_Name,Cate_ParentID=@Cate_ParentID,Cate_Image=@Cate_Image,Cate_Intro=@Cate_Intro,Cate_Order=@Cate_Order,Cate_AddTime=@Cate_AddTime,Cate_Lang=@Cate_Lang,Cate_Flag=@Cate_Flag,Cate_OpType=@Cate_OpType,Cate_Url=@Cate_Url,Cate_State=@Cate_State,Cate_Depth=@Cate_Depth,Cate_IsChild=@Cate_IsChild,Cate_Key=@Cate_Key,Cate_ModelKeyId=@Cate_ModelKeyId,Cate_IsCommentFlag=@Cate_IsCommentFlag,Cate_IsRevertFlag=@Cate_IsRevertFlag,Cate_IDPath=@Cate_IDPath,Cate_IsMember=@Cate_IsMember,Cate_MemberRole=@Cate_MemberRole,Cate_AllAction=@Cate_AllAction, Cate_Layer=@Cate_Layer,Cate_BackCate=@Cate_BackCate, Cate_magstate=@Cate_magstate, Cate_showtype=@Cate_showtype, Cate_IsCapability=@Cate_IsCapability,Cate_auditing=@Cate_auditing,Cate_browse=@Cate_browse,Cate_Guid=@Cate_Guid ,Cate_ViewURL=@Cate_ViewURL where Cate_ID=@Cate_ID";
            OleDbParameter[] cmdParms = new OleDbParameter[] { 
                new OleDbParameter("@Cate_Name", OleDbType.VarChar), new OleDbParameter("@Cate_ParentID", OleDbType.Integer), new OleDbParameter("@Cate_Image", OleDbType.VarChar), new OleDbParameter("@Cate_Intro", OleDbType.LongVarChar), new OleDbParameter("@Cate_Order", OleDbType.Integer), new OleDbParameter("@Cate_AddTime", OleDbType.DBTimeStamp), new OleDbParameter("@Cate_Lang", OleDbType.VarChar), new OleDbParameter("@Cate_Flag", OleDbType.VarChar), new OleDbParameter("@Cate_OpType", OleDbType.VarChar), new OleDbParameter("@Cate_Url", OleDbType.VarChar), new OleDbParameter("@Cate_State", OleDbType.VarChar), new OleDbParameter("@Cate_Depth", OleDbType.VarChar), new OleDbParameter("@Cate_IsChild", OleDbType.Integer), new OleDbParameter("@Cate_Key", OleDbType.VarChar), new OleDbParameter("@Cate_ModelKeyId", OleDbType.SmallInt), new OleDbParameter("@Cate_IsCommentFlag", OleDbType.SmallInt), 
                new OleDbParameter("@Cate_IsRevertFlag", OleDbType.SmallInt), new OleDbParameter("@Cate_IDPath", OleDbType.VarChar), new OleDbParameter("@Cate_IsMember", OleDbType.VarChar), new OleDbParameter("@Cate_MemberRole", OleDbType.VarChar), new OleDbParameter("@Cate_AllAction", OleDbType.VarChar), new OleDbParameter("@Cate_Layer", OleDbType.SmallInt), new OleDbParameter("@Cate_BackCate", OleDbType.SmallInt), new OleDbParameter("@Cate_magstate", OleDbType.SmallInt), new OleDbParameter("@Cate_showtype", OleDbType.SmallInt), new OleDbParameter("@Cate_IsCapability", OleDbType.SmallInt), new OleDbParameter("@Cate_auditing", OleDbType.SmallInt), new OleDbParameter("@Cate_browse", OleDbType.SmallInt), new OleDbParameter("@Cate_Guid", OleDbType.VarChar), new OleDbParameter("@Cate_ViewURL", OleDbType.VarChar), new OleDbParameter("@Cate_ID", OleDbType.Integer)
             };
            cmdParms[0].Value = model.Cate_Name;
            cmdParms[1].Value = model.Cate_ParentID;
            cmdParms[2].Value = model.Cate_Image;
            cmdParms[3].Value = model.Cate_Intro;
            cmdParms[4].Value = model.Cate_Order;
            cmdParms[5].Value = model.Cate_AddTime;
            cmdParms[6].Value = model.Cate_Lang;
            cmdParms[7].Value = model.Cate_Flag;
            cmdParms[8].Value = model.Cate_OpType;
            cmdParms[9].Value = model.Cate_Url;
            cmdParms[10].Value = model.Cate_State;
            cmdParms[11].Value = model.Cate_Depth;
            cmdParms[12].Value = model.Cate_IsChild;
            cmdParms[13].Value = model.Cate_Key;
            cmdParms[14].Value = model.Cate_ModelKeyId;
            cmdParms[15].Value = model.Cate_IsCommentFlag;
            cmdParms[0x10].Value = model.Cate_IsRevertFlag;
            cmdParms[0x11].Value = model.Cate_IDPath;
            cmdParms[0x12].Value = model.Cate_IsMember;
            cmdParms[0x13].Value = model.Cate_MemberRole;
            cmdParms[20].Value = model.Cate_AllAction;
            cmdParms[0x15].Value = model.Cate_Layer;
            cmdParms[0x16].Value = model.Cate_BackCate;
            cmdParms[0x17].Value = model.Cate_magstate;
            cmdParms[0x18].Value = model.Cate_showtype;
            cmdParms[0x19].Value = model.Cate_IsCapability;
            cmdParms[0x1a].Value = model.Cate_auditing;
            cmdParms[0x1b].Value = model.Cate_browse;
            cmdParms[0x1c].Value = model.Cate_Guid;
            cmdParms[0x1d].Value = model.Cate_ViewURL;
            cmdParms[30].Value = model.Cate_ID;
            OleDbHelper.ExecuteSql("update Dcms_Cate set Cate_IsChild=0 where Cate_ID=" + model.Cate_ParentID, null);
            OleDbHelper.ExecuteSql(sQLString, cmdParms);
            return model;
        }
    }
}

